<template>
  <div class="app-container-item">
    <div class="form-main">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" class="form-flex">
        <el-row :gutter="20">
          <el-col :span="8" :xs="24">
            <el-form-item label="小区名称" prop="communityName">
              <el-input v-model="form.communityName" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="车场名称" prop="parkingName">
              <el-input v-model="form.parkingName" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="车位名称" prop="carportName">
              <el-input v-model="form.carportName" placeholder="请输入车位名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="车位面积" prop="carportArea">
              <el-input v-model="form.carportArea" placeholder="请输入车位面积" :disabled="disabled"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="车位状态" prop="carportState">
              <el-select v-model="form.carportState" placeholder="请选择车位状态">
                <el-option
                  v-for="dict in dict.carport_state"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="车位功能" prop="carportFunction">
              <el-select v-model="form.carportFunction" placeholder="车位功能" :disabled="disabled">
                <el-option
                  v-for="item in dict.carport_function"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="排序" prop="orderNum">
              <el-input v-model="form.orderNum" placeholder="请输入排序" :disabled="disabled"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="dialog-footer" style="text-align: center;">
      <el-button type="primary" plain @click="submitForm" v-hasPermi="['property:carport:edit']">保 存</el-button>
    </div>
  </div>
</template>

<script>
  import {getCarport, updateCarport} from "@/api/property/carport";

  export default {
    name: 'parkingCarportForm',
    dicts: ['carport_state','carport_function'],
    data() {
      return {
        currentNode: {},
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    watch: {
      currentNode(v) {
        this.initForm()
      }
    },
    created() {
      this.initForm()
    },
    methods: {
      initForm() {
        this.reset();
        if (this.currentNode.modelType == 'carp') {
          getCarport(this.currentNode.id).then(response => {
            this.form = response.data;
          });
        }
      },
      // 表单重置
      reset() {
        this.form = {
          carportId: null,
          communityId: null,
          parkingId: null,
          communityName: null,
          parkingName: null,
          carportName: null,
          carportArea: null,
          carportState: null,
          carportFunction: null,
          deptId: null,
          ancestors: null,
          createBy: null,
          createTime: null,
          orderNum:99,
          updateBy: null,
          updateTime: null
        };
        this.resetForm("form");
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            updateCarport(this.form).then(response => {
              this.msgSuccess("修改车位成功");
              this.$emit("ok")
            });
          }
        });
      }
    },
    props: {
      currentNode: {
        type: Object,
        default: () => {
        }
      },
    }
  };
</script>
